#include "controlboard.h"
#include "ui_controlboard.h"
#include "meters/QMeter.h"
#include <QStringList>
#include <QString>
#include "processmanager.h"

ControlBoard::ControlBoard(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ControlBoard)
{
    ui->setupUi(this);
}

ControlBoard::~ControlBoard()
{
    delete ui;
}

void ControlBoard::carInfo(QStringList info)
{
    if(info.isEmpty())
        return;
    if(info.count()!=7)
        return;

//    setSpeed(info.at(0));
    int acce = QString(info.at(1)).toInt();
    int brake = QString(info.at(2)).toInt();
    int dir = QString(info.at(3)).toInt();
    setAcce(acce);
    setBrake(brake);
    setDir(dir);
//    setDriveMode(info.at(4));
//    setParkingBrake(info.at(5));
//    setTrafficLightFlag(info.at(6));
}

int ControlBoard::acce() const
{
    return m_acce;
}

int ControlBoard::brake() const
{
    return m_brake;
}

int ControlBoard::dir() const
{
    return m_dir;
}

void ControlBoard::on_view_mode_toggled(bool checked)
{
    if(checked)
    {
        ui->view_mode->setText("放大");
    }
    else
    {
        ui->view_mode->setText("地图");
    }
    emit viewStateChanged(checked);
}

void ControlBoard::on_start_clicked()
{
//    emit ctrlStart();
}

void ControlBoard::on_stop_clicked()
{
//    emit ctrlStop();
}

void ControlBoard::carStateChanged(bool ismove)
{
//    ui->start->setEnabled(!ismove);
//    ui->stop->setEnabled(ismove);
}

void ControlBoard::setAcce(int acce)
{
    m_acce = acce;
    ui->acce->setValue(acce);
}

void ControlBoard::setBrake(int brake)
{
    m_brake = brake;
    ui->brake->setValue(brake);
}

void ControlBoard::setDir(int dir)
{
    m_dir = dir;
    ui->meter_dir->setProperty("value", dir);
}

void ControlBoard::on_settings_clicked()
{
    emit sysSettings();
}

void ControlBoard::on_start_toggled(bool checked)
{
    if(checked)
    {
        ProcessManager::instance().startProCtrl();
        ui->start->setText("结束");
    }
    else
    {
        ProcessManager::instance().stopProCtrl();
        ui->start->setText("启动");
    }
}
